<template>
  <div>
    <div>
      <van-nav-bar title="面经登录" />
      <van-form @submit="onSubmit">
        <van-field
          :rules="[{ required: true, message: '请填写用户名' }]"
          label="用户名"
          label-width="50"
          name="username"
          placeholder="用户名"
          v-model="username"
        />
        <van-field
          :rules="[{ required: true, message: '请填写密码' }]"
          label="密码"
          label-width="50"
          name="password"
          placeholder="密码"
          type="password"
          v-model="password"
        />
        <div style="margin: 16px">
          <van-button block native-type="submit">登录</van-button>
        </div>
        <div style="text-align: right; padding-right: 20px">
          <router-link style="color: #0970a5" to="/register"
            >注册账号</router-link
          >
        </div>
      </van-form>
    </div>
  </div>
</template>
<script>
import request from '@/utils/request.js';
import { setToken } from '@/utils/storage.js'
import { loginApi } from '@/api/article.js'
export default {
  name: '',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  created () {
  },
  computed: {
  },
  methods: {
    async onSubmit (values) {
      console.log('submit', values);
      // const res = await request.post('/user/login', values)
      var res = await loginApi(values)

      console.log(res);
      setToken(res.data.token)
      this.$toast('登陆成功')
      this.$router.push('/layout')
    },
  }
}
</script>
<style lang='less'  scoped>
.van-button {
  background-color: #fa6d1d;
  color: #fff;
}
</style>
